﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpHomeEngine;

namespace Insteon
{
    public abstract class InsteonDevice : Device
    {
        internal readonly InsteonAddress InsteonAddress;
        internal readonly InsteonInterface InsteonInterface;

        internal InsteonDevice(InsteonInterface InsteonInterface, string Name, InsteonAddress InsteonAddress)
            : base(InsteonInterface, Name)
        {
            this.InsteonAddress = InsteonAddress;
            this.InsteonInterface = InsteonInterface;
        }

        /// <summary>
        /// Generates the command to change device state
        /// </summary>
        /// <param name="Tag"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        internal abstract Commands.Command GenerateStateChangeCommand(Tag Tag, Object Value);

        /// <summary>
        /// Generates the command to change device state
        /// </summary>
        /// <param name="Tag"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        internal abstract Commands.Command GenerateStateRequest(Tag Tag);


        /// <summary>
        /// A request was made to read a state. Implement this function to return the that.
        /// Only the device can tell what the state is after it is read.
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Tag"></param>
        /// <returns></returns>
        internal abstract Object ReadStateRequestResponse(Commands.Command Command, Tag Tag);


        /// <summary>
        /// A device needs to know how to handle any messages received by the interface from that device.
        /// </summary>
        /// <param name="Message"></param>
        internal abstract void HandleUnsolicitedMessage(Messages.Message Message);

        internal void UnsolicitedTagChange(Tag Tag, object Value)
        {
            this.InsteonInterface.UnsolicitedTagChange(this, Tag, Value);
        }

    }
}
